package array;

public class leetCode739_dailyTemperatures {
    public static void main(String[] args) {
        leetCode739_dailyTemperatures a = new leetCode739_dailyTemperatures();
        int[] nums = {73,74,75,71,69,72,76,73};
        a.dailyTemperatures(nums);
    }
    public int[] dailyTemperatures(int[] temperatures) {
        if(temperatures == null || temperatures.length == 0)return new int[]{};
        int[] result = new int[temperatures.length];
        int n = temperatures.length;
        for (int i = n - 2; i >= 0; i--) {
            for (int j = i + 1; j < temperatures.length; j+=result[j]) {
                if(temperatures[j] > temperatures[i]){
                    result[i] = j - i;
                    break;
                }else if(result[j] == 0){
                    result[i] = 0;
                    break;
                }
            }

        }
        return result;
    }
}
